<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>权限选择</title>
    <meta name="ctx" th:content="${#httpServletRequest.getContextPath()}"/>
    <link rel="stylesheet" th:href="@{/css/admin/base-v2.css}">
    <link rel="stylesheet" th:href="@{/lib/font-awesome/4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/css/admin/app.css}">
    <link rel="stylesheet" th:href="@{/css/admin/menu-select.css}">
</head>

<body>

<div class="app-page">

    <div class="app-page-content">

        <div class="app-card">
            <div class="app-card-body">
                <div class="app-card-body-con">
                    <!--<div class="ztree"></div>-->
                    <div class="menu-select"></div>
                </div>
            </div>
        </div>

    </div>

</div>

<script th:src="@{/lib/jquery.min.js}"></script>
<script th:src="@{/lib/layer-v3.1.1/layer/layer.js}"></script>
<script th:src="@{/js/popup.js}"></script>
<script th:src="@{/js/form.js}"></script>
<script th:src="@{/js/admin/app.js}"></script>
<script th:src="@{/js/pagination.js}"></script>
<!--<script th:src="@{/js/tree.js}"></script>-->
<script th:src="@{/lib/vue/v2.5.16/vue.min.js}"></script>
<script th:src="@{/js/admin/menu-select.js}"></script>
<script type="text/javascript" th:inline="javascript">
    //获取context path
    var context = $("meta[name='ctx']").attr("content") || '';

    var roleId = [[${roleId}]];

    var tree = null;

    $(function () {
        initTree();
    })

    function initTree() {
        var data = null;

        var url = context + "/module/listModuleTree";
        if (roleId) {
            url += '?roleId=' + roleId;
        }

        //权限列表
        $.ajax({
            type: "POST",
            url: url,
            // type: "JSON",
            success: function (obj) {
                var code = obj.code;
                if (code == 0) {
                    setTree(obj.data);
                }
            }
        })

        function setTree(data) {
            MenuSelect.menuData = data;
            // 树形控件
            // tree = new Tree('.ztree', {
            //     type: 1,
            //     data: data
            // })
        }
    }

    // 获取树形控件数据
    function getTreeData() {
        var idsdata = [];
        var namedata = [];
        MenuSelect.checked.forEach(function (treeItem) {
            // if (treeItem.checked) {
                idsdata.push(treeItem.moduleId);
                namedata.push(treeItem.label);
            // }
        })
        return {
            idsdata: idsdata.join(','),
            namedata: namedata.join(',')
        };
    }

    // 加载select联动内容
    $('[name="searchType"] option').each(function (index, element) {
        if ((App.query.searchType === undefined && index === 0) || App.query.searchType == $(this).val()) {
            $('.j-option-switch .content').html($(".search").children('div').eq(index).html())
        }
    })

</script>
</body>

</html>